home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / test / lib / scan.c < prev    next >
C/C++ Source or Header  |  1992-11-23  |  876b  |  42 lines

  1.  
  2.  
  3. /*
  4.  *  SCAN TEST
  5.  */
  6.  
  7. #include <stdio.h>
  8.  
  9. main()
  10. {
  11.     char buf[128];
  12.     char buf2[128];
  13.     int n;
  14.     char c;
  15.  
  16.     printf("addrs %08lx %08lx ", &c, buf);
  17.     printf("Please enter a line -");
  18.     fflush(stdout);
  19.     n = scanf("%c%s", &c, buf);
  20.     printf("n = %d, c = $%02x result = '%s'\n", n, c, buf);
  21.     printf("char after (nl) = %02x\n", getc(stdin));
  22.     printf("Please enter another line-");
  23.     fflush(stdout);
  24.     if (gets(buf) == NULL) {
  25.     puts("That was EOF!");
  26.     } else {
  27.     int n1, n2;
  28.     printf("addrs %08lx %08lx ", &c, buf2);
  29.     n = sscanf(buf, "%c%s", &c, buf2);
  30.     printf("And this time n =%d, c = $%02x, s = '%s'\n", n, c, buf);
  31.  
  32.     printf("Now, enter two numbers-");
  33.     fflush(stdout);
  34.     if (gets(buf)) {
  35.         printf("addrs %08lx %08lx ", &n1, &n2);
  36.         n = sscanf(buf, "%d %d", &n1, &n2);
  37.         printf("Result n = %d numbers %d and %d\n", n, n1, n2);
  38.     }
  39.     }
  40. }
  41.  
  42.